package vy.org.app.common;


import java.io.File;
import java.net.URL;
import java.util.Properties;

import vy.org.app.common.Logger.LogLevel;

public class Config {
	private static final Properties prop = new Properties();

	static {
		try {
			URL url = Config.class.getResource(".."+ File.separator + 
					".."+ File.separator + 
					".."+ File.separator + 
					".."+ File.separator + "Config.properties");
			String path = url.getPath();
			int idx = path.indexOf("WEB-INF/classes/Config.properties"),
				idw = path.indexOf("webapps/");
			String appName = path.substring(idw+7,idx-1);
			path = path.substring(1,idx-1);
			System.out.println("absolutepath :" + path);
			System.out.println("absolutepath :" + appName);
			prop.put("APP_PATH", "/VyManagement");
			prop.put("FILE_PATH", path+"/WEB-INF/dump/");
			prop.put("UPLOAD_PATH", path+"/bulkupload/");
			
			File filePath = new File(prop.getProperty("FILE_PATH"));
			if(filePath.exists()){
				filePath.mkdirs();
			}
			filePath = new File(prop.getProperty("UPLOAD_PATH"));
			if(filePath.exists()){
				filePath.mkdirs();
			}
		} catch (Exception e) {
			Logger.log(LogLevel.ERROR, e);
		}
	}

	public static String getAppPath() {
		return prop.getProperty("APP_PATH");
	}

	public static String getProperty(String name) {
		return prop.getProperty(name);
	}
}
